﻿<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" Codebehind="AddPersonalProject.aspx.cs"
    Inherits="LabMS.Web.PersonalProject.AddPersonalProject" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>实验室开发申请表</title>
    <link type="text/css" rel="stylesheet" href="../style/screen.css" />
    <!--[if lte IE 6]>
    <link type="text/css" rel="stylesheet" href="../style/ie6.css" />
    <![endif]-->
    <!--[if lte IE 7]>
    <link type="text/css" rel="stylesheet" href="../style/ie7.css" />
    <![endif]-->

    <script src="../../js/calendar5.js" type="text/javascript"></script>

    <script type="text/javascript">
    var d = new Calendar("d");
    document.write(d);
    </script>

</head>
<body class="mainBody">
    <form id="form1" runat="server">
        <div class="main">
            <div id="pageInfo" class="clearfix">
                <div class="title">
                    <label>
                        <a href="ListPersonalProject.aspx">学生自拟开放实验申请列表</a></label>&gt;新增学生自拟开放实验申请
                </div>
            </div>
        </div>
        <div class="main">
            <p>
                <asp:Button ID="btnSave" runat="server" CssClass="button" OnClick="btnSave_Click"
                    Text="保存" />
                <asp:Button ID="btnApply" runat="server" CssClass="button" Text="申请" OnClick="btnSave_Click" />
                <input id="btnReturn" class="button" type="button" onclick="javascript:window.location.href='ListPersonalProject.aspx';"
                    value="返回" />
            </p>
            <table cellpadding="2" cellspacing="0" border="0">
                <tr>
                    <td>
                        <label class="itemTitle">
                            项目名称：</label><span style="color: Red">*</span>
                    </td>
                    <td>
                        <asp:TextBox ID="ProjectName" runat="server" MaxLength="25"></asp:TextBox>
                    </td>
                    <td>
                        <label class="itemTitle">
                            计划学时：</label><span style="color: Red">*</span>
                    </td>
                    <td>
                        <asp:TextBox ID="PlanHours" runat="server" MaxLength="4"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="itemTitle">
                            申请实验室：</label><span style="color: Red">*</span>
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlApplyLab" DataTextField="Lab_Name" DataValueField="ID" runat="server">
                        </asp:DropDownList>
                    </td>
                    <td>
                        <label class="itemTitle">
                            申请时间：</label><span style="color: Red">*</span>
                    </td>
                    <td>
                        <asp:TextBox ID="ApplyTimeMin" Width="56" runat="server"></asp:TextBox>--<asp:TextBox
                            ID="ApplyTimeMax" Width="56" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr valign="top">
                    <td>
                        <label class="itemTitle">
                            申请人：</label><span style="color: Red">*</span>
                    </td>
                    <td>
                        <input type="button" id="btAddApplicant" runat="server" class="button" value="添加申请人"
                            onclick="OpenEditWin('../CommonPage/studentslist.aspx',500,400)" />
                        <div id="studentlist" runat="server" style="margin-top: 5px;">
                        </div>
                        <input id="tblistEmpty" style="display: none" value="1" runat="server" type="text" />
                        <input id="tblistStudents" style="display: none" value="" runat="server" type="text" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="itemTitle">
                            联系人：</label><span style="color: Red">*</span>
                    </td>
                    <td>
                        <asp:TextBox ID="Contactor" runat="server" MaxLength="25"></asp:TextBox>
                    </td>
                    <td>
                        <label class="itemTitle">
                            班级：</label>
                    </td>
                    <td>
                        <asp:TextBox ID="ContactorClass" runat="server" MaxLength="25"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="itemTitle">
                            联系电话：</label><span style="color: Red">*</span>
                    </td>
                    <td>
                        <asp:TextBox ID="ContactPhone" runat="server" MaxLength="25"></asp:TextBox>
                    </td>
                    <td>
                        <label class="itemTitle">
                            E-Mail：</label>
                    </td>
                    <td>
                        <asp:TextBox ID="ContactEmail" runat="server" MaxLength="25"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="itemTitle">
                            指导老师：</label>
                    </td>
                    <td>
                        <asp:TextBox ID="Teacher" runat="server" MaxLength="25"></asp:TextBox>
                    </td>
                    <td>
                        <label class="itemTitle">
                            职称：</label>
                    </td>
                    <td>
                        <asp:TextBox ID="TeacherTitle" runat="server" MaxLength="25"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="itemTitle">
                            联系电话：</label>
                    </td>
                    <td>
                        <asp:TextBox ID="TeacherPhone" runat="server" MaxLength="25"></asp:TextBox>
                    </td>
                    <td>
                        <label class="itemTitle">
                            E-Mail：</label>
                    </td>
                    <td>
                        <asp:TextBox ID="TeacherEmail" runat="server" MaxLength="25"></asp:TextBox>
                    </td>
                </tr>
                <tr valign="top">
                    <td>
                        <label class="itemTitle">
                            所需仪器：</label>
                    </td>
                    <td>
                        <p>
                            <input type="button" class="button" id="btnAddEquip" runat="server" value="添加仪器"
                                onclick="CreateTable()" /></p>
                        <table id="tableEquip" class="infoTable" border="1" cellspacing="0" cellpadding="2"
                            style="border-collapse: collapse;">
                            <thead>
                                <tr class="header">
                                    <th style="display: none">
                                        编号</th>
                                    <th>
                                        名称</th>
                                    <th>
                                        数量</th>
                                    <th>
                                        备注</th>
                                    <th>
                                    </th>
                                </tr>
                            </thead>
                        </table>
                        <input id="tbTableEquip" style="display: none" runat="server" value="" type="text" />
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                </tr>
                <tr valign="top">
                    <td>
                        <label class="itemTitle">
                            所需低耗品：</label>
                    </td>
                    <td>
                        <p>
                            <input type="button" id="btnAddLowConsumption" class="button" runat="server" value="添加低耗品"
                                onclick="CreateTable2()" />
                        </p>
                        <table id="tableConsump" class="infoTable" border="1" cellspacing="0" cellpadding="2"
                            style="border-collapse: collapse;">
                            <thead>
                                <tr class="header">
                                    <th style="display: none">
                                        编号</th>
                                    <th>
                                        名称</th>
                                    <th>
                                        数量</th>
                                    <th>
                                        备注</th>
                                    <th>
                                    </th>
                                </tr>
                            </thead>
                        </table>
                        <input id="tbTableConsump" style="display: none" runat="server" value="" type="text" />
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        <label class="itemTitle">
                            申请理由：</label>
                    </td>
                    <td colspan="3">
                        <asp:TextBox ID="ApplyReason" TextMode="MultiLine" Rows="8" Width="380" Height="100"
                            runat="server" MaxLength="250"></asp:TextBox>
                    </td>
                </tr>
            </table>
            <asp:TextBox ID="tb_StudentIDs" Style="display: none" runat="server" />
            <input id="tb_EIndex" style="display: none" runat="server" value="0" type="text" />
            <input id="tb_ConsumpIndex" style="display: none" runat="server" value="0" type="text" />
        </div>
    </form>

    <script type="text/javascript" src="../js/jQuery/jquery-1.3.1.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.json-1.3.min.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.validate.js"></script>

    <script type="text/javascript">
    function OpenEditWin(frmWin,width,height) 
      {       
       var me; 
           me = window;  
           var ret = window.showModalDialog (frmWin, me, 'dialogWidth='+width +'px;dialogHeight='+height+'px;help:no;status:no');
            
          if (ret != null) 
           { 
                var strTable = ""; 
                var listEmpty = $("#tblistEmpty").val();
                if(listEmpty=="1")
                {  
                    var HTML = "<table id='studenlist' class='infoTable' border='1' style='width: 185px; border-collapse: collapse;'>";
                    HTML += "<thead>";
                    HTML += "<tr class='header'>";
                    HTML += "<td class='none'>";
                    HTML += "ID";
                    HTML += "</td>";

                    HTML += "<td>";
                    HTML += "学号";
                    HTML += "</td>";

                    HTML += "<td>";
                    HTML += "姓名";
                    HTML += "</td>";
                    HTML += "<td>";
                    HTML += "";
                    HTML += "</td>"; 
                    HTML += "</tr>";
                    HTML += "</thead>"; 
                    strTable +=   HTML;
                   $("#tblistEmpty").val(0); 
                }
                
                var HTML2 = ""; 
                var value=$("#tb_StudentIDs").val();
                var listID = value.split(',');
                 for(var j=0; j<ret.Items.length; ++j)
                {
                    var item = ret.Items[j];
                   if(value!=""){
                        var HasID = false;
                        for(var i=0; i<listID.length; ++i)
                        {
                            if(listID[i] == item.ID)
                           {
                            HasID = true; 
                            }  
                        } 
                        if(!HasID)
                        { 
                            HTML2 += "<tr>"; 
                            HTML2 += "<td class='none'>"; 
                            value=value+","+item.ID; 
                            $("#tb_StudentIDs").val(value);  
                            HTML2 += item.ID; 
                            HTML2 += "</td>"; 
                            HTML2 += "<td>"; 
                            HTML2 += item.Code; 
                            HTML2 += "</td>";
                            HTML2 += "<td>"; 
                            HTML2 += item.Name; 
                            HTML2 += "</td>";
                           HTML2 += "<td>"; 
                            HTML2 += "<a>删除</a>"; 
                            HTML2 += "</td>"; 
                            HTML2 += "</tr>";  
                            strTable +=   HTML2; 
                           HTML2 = ""; 
                        }   
                    }else
                    {
                        HTML2 += "<tr>"; 
                        HTML2 += "<td class='none'>"; 
                        value=item.ID;
                        HTML2 += item.ID; 
                        HTML2 += "</td>"; 
                        HTML2 += "<td>"; 
                        HTML2 += item.Code; 
                        HTML2 += "</td>";
                        HTML2 += "<td>"; 
                        HTML2 += item.Name; 
                        HTML2 += "</td>";
                        HTML2 += "<td>"; 
                        HTML2 += "<a>删除</a>"; 
                        HTML2 += "</td>";
                        HTML2 += "</tr>";  
                        strTable +=   HTML2; 
                        HTML2 = ""; 
                    }       
                }
                $("#tb_StudentIDs").val(value); 
                 
                if(listEmpty=="1")
                {  
                    var HTML3 = "</table>";
                    strTable +=   HTML3;    
                    $("#studentlist").append(strTable); 
                }
                else
                {
                    $("#studentlist").children().children("tbody").append(strTable);
                }
                $("#tblistStudents").val($("#studentlist").html());
                
               $("#studentlist  a").css("cursor","pointer"); 
              
               
              $("#studentlist  a").click( function () 
                                     { 
                                        var strsID = $(this).parent().parent().children().html();
                                        var listID = $("#tb_StudentIDs").val().split(',');
                                        var value = "";
                                          for(var i=0; i<listID.length; ++i)
                                         {
                                             if(listID[i] != strsID)
                                            {
                                                  if(value=="")
                                                 {
                                                    value = listID[i];
                                                 } 
                                                 else
                                                {
                                                    value += "," + listID[i];
                                                }  
                                             }
                                               
                                         } 
                                        $("#tb_StudentIDs").val(value); 
                                        $(this).parent().parent().remove();
                                        if($("#tb_StudentIDs").val()=="")
                                        {
                                            $("#studentlist").html("");
                                            $("#tblistEmpty").val(1); 
                                        }
                                           $("#tblistStudents").val($("#studentlist").html()); 
                                 }); 
              
           }  
      }
      
       //1:编号,2:名称
     function OpenEditWin2(frmWin,width,height,obj1, obj2) 
      {       
           var me; 
           me = window;  
           var ret = window.showModalDialog(frmWin,me,'dialogWidth='+width +'px;dialogHeight='+height+'px;help:no;status:no');
              if (ret != null) 
            { 
                document.getElementById(obj1).value = ret[0];
                document.getElementById(obj2).value = ret[1];
                $("#tbTableEquip").val($("#tableEquip").html());
            }  
      } 
      
      function CreateTable()
      {
        var index = $("#tb_EIndex").val();
        var table = "<tr>";
        table += "<td style='display:none'>";
        table += "<input id='code"+index+"' type='text' />";
        table += "</td>";
        table += "<td>";
        table += "<input style='width:40px;' name='name"+index+"' id='name"+index+"' type='text' /><input  onclick=OpenEditWin2('../CommonPage/consumselectlist.aspx?location=@ALL@&Type=yiqi',500,400,'code"+index+"','name"+index+"'); type='button' class='button' value='...' /> ";
        table += "</td>";
        
        table += "<td>";
        table += "<input style='width:30px;' name='num"+index+"' id='num"+index+"' type='text' />";
        table += "</td>";
        table += "<td>";
        table += "<input style='width:50px;' name='intro"+index+"' id='intro"+index+"' type='text' />";
        table += "</td>";
        table += "<td>";
        table += "<a>删除</a>";
        table += "</td>";
        table += "</tr>";
        $("#tableEquip").append(table);
        $("#tbTableEquip").val($("#tableEquip").html());
        var count=parseInt(index) + 1;
        $("#tb_EIndex").val(count);
        
        $("#tableEquip a").click(function()
         { 
            $(this).parent().parent().remove();
            $("#tbTableEquip").val($("#tableEquip").html());
         });        
    }

       
      //1:编号,2:名称
     function OpenEditWin3(frmWin,width,height,obj1, obj2) 
      {       
           var me; 
           me = window;  
           var ret = window.showModalDialog(frmWin,me,'dialogWidth='+width +'px;dialogHeight='+height+'px;help:no;status:no');
              if (ret != null) 
            { 
                document.getElementById(obj1).value = ret[0];
                document.getElementById(obj2).value = ret[1];
                $("#tbTableConsump").val($("#tableConsump").html());
            }  
      } 
      
    function CreateTable2()
      {
        var index = $("#tb_ConsumpIndex").val();
        
        var table = "<tr>";
        table += "<td style='display:none'>";
        table += "<input id='consumpcode"+index+"' type='text' />";
        table += "</td>";
        table += "<td>";
        table += "<input style='width:40px;' name='consumpname"+index+"' id='consumpname"+index+"' type='text' /><input  onclick=OpenEditWin3('../CommonPage/consumselectlist.aspx?location=@ALL@&Type=xiaohaopin',500,400,'consumpcode"+index+"','consumpname"+index+"'); type='button' class='button' value='...' /> ";
        table += "</td>";
        
        table += "<td>";
        table += "<input style='width:30px;' name='consumpnum"+index+"' id='consumpnum"+index+"' type='text' />";
        table += "</td>";
        table += "<td>";
        table += "<input style='width:50px;' name='consumpintro"+index+"' id='consumpintro"+index+"' type='text' />";
        table += "</td>";
        table += "<td>";
        table += "<a>删除</a>";
        table += "</td>";
        table += "</tr>";
        
        $("#tableConsump").append(table);
        $("#tbTableConsump").val($("#tableConsump").html());
        var count=parseInt(index) + 1;
        $("#tb_ConsumpIndex").val(count);
        
        $("#tableConsump a").click(function()
         { 
            $(this).parent().parent().remove();
            $("#tbTableConsump").val($("#tableConsump").html());
         }); 
       }
       
      $(document).ready(function(){ 
         var temp = $("#tbTableEquip").val();
          if(temp!="")
          {
             $("#tableEquip").html($("#tbTableEquip").val());
              $("#tableEquip a").click(function()
             { 
                $(this).parent().parent().remove();
               $("#tbTableEquip").val($("#tableEquip").html());
             }); 
          }
          
          temp = $("#tbTableConsump").val();
          if(temp!="")
          {
             $("#tableConsump").html($("#tbTableConsump").val());
              $("#tableConsump a").click(function()
             { 
                $(this).parent().parent().remove();
               $("#tbTableConsump").val($("#tableConsump").html());
             }); 
          }   
          
           $("#form1").validate({
            rules: {
                ProjectName: {
                    required:true
                },
                PlanHours: {
                    required:true,
                    number:true
                },
                ApplyTimeMin: "required",
                ApplyTimeMax: "required",
                Contactor: "required",
                ContactPhone: {
                    required:true,
                    number:true,
                },
                ContactEmail: {
                    email:true
                },
                TeacherPhone: {
                    number:true
                },
                TeacherEmail: {
                    email:true
                }
            },
            messages: {
                ProjectName:{
                    required:"请输入项目名称"
                },
                PlanHours:{
	                required:"请输入计划学时",
	                number:"请输入数字"
	            },
                ApplyTimeMin:"请输入申请开始时间",
                ApplyTimeMax:"请输入申请结束时间",
                Contactor:"请输入联系人",
                ContactPhone: {
                    required:"请输入联系电话",
                    number:"请输入数字"
                },
                ContactEmail: {
                    email:"请输入正确格式的E-Mail"
                },
                TeacherPhone: {
                    number:"请输入数字"
                },
                TeacherEmail: {
                    email:"请输入正确格式的E-Mail"
                }
            }
        });
        
         if($("#tblistStudents").val() !="" )
            $("#studentlist").html($("#tblistStudents").val());

        $("#studentlist  a").css("cursor","pointer"); 

        $("#studentlist  a").click( function (){
            var strsID = $(this).parent().parent().children().html();
            var listID = $("#tb_StudentIDs").val().split(',');
            var value = "";
            for(var i=0; i<listID.length; ++i) {
                if(listID[i] != strsID) {
                    if(value=="") {
                        value = listID[i];
                    } else {
                        value += "," + listID[i];
                    }
                 }
            }

            $("#tb_StudentIDs").val(value);
            $(this).parent().parent().remove();

            if($("#tb_StudentIDs").val()=="") {
                $("#studentlist").html("");
                $("#tblistEmpty").val(1); 
            }

            $("#tblistStudents").val($("#studentlist").html());
        });
            
       }); 

    </script>

</body>
</html>
